package everyday;

import java.util.Arrays;

public class T1419 {
    public int minNumberOfFrogs(String croakOfFrogs) {
        char[] PRE = new char['s'];
        int[] cnt = new int['s'];
        char[] t = "croakc".toCharArray();
        for (int i = 1; i < t.length; i++) {
            PRE[t[i]] = t[i - 1];
        }
        for (char c : croakOfFrogs.toCharArray()) {
            char l = PRE[c];
            if (cnt[l] > 0) {
                cnt[l]--;
            } else if (c != 'c') {
                return -1;
            }
            cnt[c]++;
        }
        return Arrays.stream(cnt).sum() == cnt['k'] ? cnt['k'] : -1;
    }
}
